//
//  YSOrderCell.m
//  Yueshi
//
//  Created by Northwan on 15/8/3.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//

#import "YSOrderCell.h"

@interface YSOrderCell()
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *numLabel;
@property (weak, nonatomic) IBOutlet UILabel *buyLinkLabel;

@end

@implementation YSOrderCell

+(instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *CellIdentiferId = @"YSOrderCell";
    YSOrderCell *cell =  [tableView dequeueReusableCellWithIdentifier:CellIdentiferId];
    if(cell == nil){
        NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"YSOrderCell" owner:nil options:nil];
        cell = [nibs lastObject];
    }
    return cell;
}

-(void)setProduct:(YSCartProduct *)product{
    _product = product;
    [self.iconView setImageURLStr:product.prodImageUrl];
   
    if(product.isPresent){
         NSString *prodName = [NSString stringWithFormat:@"(赠)%@",product.prodName];
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:prodName];
        [str addAttribute:NSForegroundColorAttributeName value:ThemeColor range:NSMakeRange(0,3)];
        [self.nameLabel setAttributedText:str];
    }
    else if(product.prodPromotion && product.prodPromotion.price){
        NSString *prodName = nil;
        if(product.prodPromotion.isPanicBuy){
            prodName = [NSString stringWithFormat:@"(抢)%@",product.prodName];
        }
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:prodName];
        [str addAttribute:NSForegroundColorAttributeName value:ThemeColor range:NSMakeRange(0,3)];
        [self.nameLabel setAttributedText:str];
    }else{
        [self.nameLabel setText:product.prodName];
    }
    [self.buyLinkLabel setText:product.prodBuyLink];
    [self.priceLabel setText:[NSString stringWithFormat:@"¥%.1f",product.prodNewPrice]];
    [self.numLabel setText:[NSString stringWithFormat:@"x%ld",product.prodCount]];
}

@end
